package com.bydq.patrolsystem.handler;

import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.type.TypeFactory;
import com.fasterxml.jackson.databind.util.Converter;

import java.text.SimpleDateFormat;
import java.util.Date;

public class DateConverter implements Converter<String, Date> {

    private final SimpleDateFormat smf =  new SimpleDateFormat("yyyy-MM-dd");

    @Override
    public Date convert(String value) {
        if ("".equals(value) || null == value) {
            return null;
        }

        try {
            return smf.parse(value);
        }catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public JavaType getInputType(TypeFactory typeFactory) {
        return null;
    }

    @Override
    public JavaType getOutputType(TypeFactory typeFactory) {
        return null;
    }
}
